﻿using University.Workshop.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for LogOnManagerTest and is intended
    ///to contain all LogOnManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class LogOnManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for LogOn
        ///</summary>
        [TestMethod()]
        public void LogOnTest()
        {
            Random rand = new Random();
            string email = "juan" + rand.Next(0, 1000) + "@hotmail.com";
            UserRegistrationManager.RegisterUser("Juan", "Perez", 'M', DateTime.Now, email, "qwerty1", "qwerty1", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string password = "qwerty1"; 
            User expected=new User(); 
            expected.ContactInformation.Email = email;
            expected.Password = password.GetHashCode().ToString();
            User actual;
            actual = LogOnManager.LogOn(email, password);
            Assert.AreEqual(expected.ContactInformation.Email, actual.ContactInformation.Email);
            Assert.AreEqual(expected.Password, actual.Password);
        }
        [TestMethod()]
        [ExpectedException(typeof(BusinessException))]
        public void LogOnTestFailed()
        {
            string email = "juan.com";
            string password = "as";
            User expected = new User();
            expected.ContactInformation.Email = email;
            expected.Password = password;
            User actual;
            actual = LogOnManager.LogOn(email, password);
            Assert.AreNotEqual(expected, actual);
        }
        /// <summary>
        ///A test for GetUser
        ///</summary>
        [TestMethod()]
        public void GetUserTest()
        {
            UserRegistrationManager.RegisterUser("Juan", "Perez", 'M', DateTime.Now, "juan@hotmail.com", "password123", "password123", "Cochabamba", "Cochabamba", "79718989", "4483251");
            string email = "juan@hotmail.com"; 
            User expected=new User(); 
            expected.ContactInformation.Email = email;
            User actual;
            actual = LogOnManager.GetUser(email);
            Assert.AreEqual(expected.ContactInformation.Email, actual.ContactInformation.Email);
            
        }
        [TestMethod()]
        public void GetUserTestFailed()
        {
            string email = "juan.com";
            User expected = new User();
            expected.ContactInformation.Email = email;
            User actual;
            actual = LogOnManager.GetUser(email);
            Assert.AreEqual(actual,null);
        }
    }
}
